package cn.maszy.service.impl.projectmanagement;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.projectmanagement.C_T_Sys_FileTypeMapper;
import cn.maszy.model.projectmanagement.C_T_Sys_FileType;
import cn.maszy.model.projectmanagement.C_T_Sys_FileTypeExample;
import cn.maszy.model.projectmanagement.C_T_Sys_FileTypeExample.Criteria;
import cn.maszy.service.projectmanagement.C_T_Sys_FileTypeService;
@Service
public class C_T_Sys_FileTypeServiceImpl implements C_T_Sys_FileTypeService {
	
	@Autowired
	private C_T_Sys_FileTypeMapper c_T_Sys_FileTypeMapper;

	public int update(C_T_Sys_FileType c_T_Sys_FileType) {
		// TODO Auto-generated method stub
		 if(c_T_Sys_FileType.getFiletypeId() == null || "".equals(c_T_Sys_FileType.getFiletypeId())){
			 c_T_Sys_FileType.setFiletypeId(UUID.randomUUID().toString());
			 c_T_Sys_FileType.setIsDelete(0);
			 c_T_Sys_FileType.setCreateTime(new Date());
			 c_T_Sys_FileType.setCreateUser(SessionFactory.getSessionUserRealNam());
			 return c_T_Sys_FileTypeMapper.insert(c_T_Sys_FileType);
		 }
		 else
		 {
			 c_T_Sys_FileType.setUpdateTime(new Date());
			 c_T_Sys_FileType.setUpdateUser(SessionFactory.getSessionUserRealNam());
			 return c_T_Sys_FileTypeMapper.updateByPrimaryKeySelective(c_T_Sys_FileType);
		 }
	}

	public C_T_Sys_FileType selectOne(String staffId) {
		// TODO Auto-generated method stub
		C_T_Sys_FileType record=c_T_Sys_FileTypeMapper.selectByPrimaryKey(staffId);
		if(staffId == null){
			record = new C_T_Sys_FileType();
		}
		return record;
	}

	public Pager<C_T_Sys_FileType> selectList(C_T_Sys_FileType c_T_Sys_FileType, Pager<C_T_Sys_FileType> pager,String moduleName) {
		// TODO Auto-generated method stub
		// 添加查询条件
		C_T_Sys_FileTypeExample example=new C_T_Sys_FileTypeExample();
				Criteria criteria = example.createCriteria();
					if(c_T_Sys_FileType!=null){
					if(c_T_Sys_FileType.getFileTypeName()!=null && !"".equals(c_T_Sys_FileType.getFileTypeName())){
						criteria.andFileTypeNameLike("%"+c_T_Sys_FileType.getFileTypeName()+"%");
					} 
				}
				criteria.andModuleNameEqualTo(moduleName);
				criteria.andIsDeleteEqualTo(0);
				example.or(criteria);
				int totalCount=new C_T_Sys_FileTypeServiceImpl().count(example,c_T_Sys_FileTypeMapper);
				pager.setTotalRecords(totalCount);
				example.setLimitStart(pager.getStartRecord());
				example.setLimitEnd(pager.getPageSize());
				example.setOrderByClause(pager.getOrderField()+" "+pager.getOrderDirection());
				
				// 取得总的记录条数
				List<C_T_Sys_FileType>  list=c_T_Sys_FileTypeMapper.selectByExample(example);
				pager.setPageRecords(list);
				return pager;
			}
	/**
	 * 返回一个list
	 */
	public List<C_T_Sys_FileType> selectLists(C_T_Sys_FileType c_T_Sys_FileType,String moduleName) {
		// TODO Auto-generated method stub
				// 添加查询条件
				C_T_Sys_FileTypeExample example=new C_T_Sys_FileTypeExample();
				Criteria criteria = example.createCriteria();
				criteria.andModuleNameEqualTo(moduleName);
				criteria.andIsDeleteEqualTo(0);
				example.or(criteria);
				// 取得总的记录条数
				List<C_T_Sys_FileType>  list=c_T_Sys_FileTypeMapper.selectByExample(example);
				return list;
			}

	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		for (String id : checkIds.split(", ")) {
			c_T_Sys_FileTypeMapper.deleteByPrimaryKey(id);
		}
		return 1;
	}

	public int count(C_T_Sys_FileTypeExample example,C_T_Sys_FileTypeMapper c_T_Sys_FileTypeMapper) {
		// TODO Auto-generated method stub
		return c_T_Sys_FileTypeMapper.countByExample(example);
	}

}
